from django.contrib import admin
from .models import CloudAccount, Domain, DNSRecord, OperationLog


@admin.register(CloudAccount)
class CloudAccountAdmin(admin.ModelAdmin):
    list_display = ('name', 'provider', 'is_active', 'created_at')
    list_filter = ('provider', 'is_active')
    search_fields = ('name', 'access_key')
    exclude = ('secret_key',)  # 不在管理界面显示敏感信息


@admin.register(Domain)
class DomainAdmin(admin.ModelAdmin):
    list_display = ('name', 'cloud_account', 'is_active', 'last_sync', 'created_at')
    list_filter = ('cloud_account__provider', 'is_active')
    search_fields = ('name',)


@admin.register(DNSRecord)
class DNSRecordAdmin(admin.ModelAdmin):
    list_display = ('name', 'domain', 'record_type', 'value', 'ttl', 'is_active')
    list_filter = ('record_type', 'domain', 'is_active')
    search_fields = ('name', 'value')
    list_per_page = 50


@admin.register(OperationLog)
class OperationLogAdmin(admin.ModelAdmin):
    list_display = ('user', 'action', 'resource_type', 'description', 'created_at')
    list_filter = ('action', 'resource_type', 'created_at')
    search_fields = ('description', 'user__username')
    readonly_fields = ('created_at',)
    list_per_page = 100
